package com.jsmtr.rms.controller;

import com.jsmtr.rms.entity.BaseUser;
import com.jsmtr.rms.entity.Duserremark;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.service.impl.UtilService;
import com.jsmtr.rms.utils.DateTools;
import com.jsmtr.rms.utils.ResultBean;
import com.jsmtr.rms.utils.StringTools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 应聘者个人情况控制器
 * @author: cyx
 * @description:
 * @date: Created in 2019/1/3 14:21
 * @modified by:
 */
@Controller
public class DoDUserRemarkController {

    @Resource
    private IUtilService utilService;


    @ResponseBody
    @RequestMapping(value = "/SaveUserRemark")
    public ResultBean SaveUserRemark(HttpServletRequest request, HttpServletResponse response, Duserremark duserremark){
        ResultBean resultBean=new ResultBean();
        if (duserremark==null||duserremark.getFid()==null||duserremark.getPid()==null||duserremark.getRid()==null){
            resultBean.setState(false);
            resultBean.setMessage("个人情况获取异常！");
            return resultBean;
        }
        try {
            BaseUser usr=utilService.getSessionUser(request);
            List<Duserremark> duserremarkList=utilService.getDuserremark(duserremark);
            if (duserremarkList.size()<=0){
                duserremark.setId(UUID.randomUUID().toString());
                duserremark.setAddtime(DateTools.toLenStr(new Date()));
                duserremark.setAdduser(usr.getUname());
                duserremark.setAddusercode(usr.getUcode());
                utilService.addObject(duserremark);
            }else{
                Duserremark   uduserremark=duserremarkList.get(0);
                uduserremark.setContent(duserremark.getContent());
                uduserremark.setEdittime(DateTools.toLenStr(new Date()));
                uduserremark.setEdituser(usr.getUname());
                uduserremark.setEditusercode(usr.getUcode());
                utilService.editObject(uduserremark);
            }
            resultBean.setState(true);
            resultBean.setMessage("操作成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败！");
        }
        return  resultBean;
    }
}
